{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import sys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from src.network_utils.shapes import *\n",
    "from src.utils.spikes_utils import *\n",
    "from src.utils.constants import GAUSSIAN_WEIGHTS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "cam_res = 12\n",
    "stride = 2\n",
    "w = 1\n",
    "d = 1\n",
    "t = hor_connections(cam_res, 0, 0, stride, cam_res, w, d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(24, 0, 0.054, 1), (28, 0, 0.054, 1), (14, 0, 0.3989, 1), (13, 0, 0.242, 1), (16, 0, 0.054, 1), (15, 0, 0.242, 1), (2, 0, 0.3989, 1), (1, 0, 0.242, 1), (3, 0, 0.242, 1), (26, 0, 0.3989, 1), (25, 0, 0.242, 1), (12, 0, 0.054, 1), (27, 0, 0.242, 1), (0, 0, 0.054, 1), (4, 0, 0.054, 1)]\n",
      "15\n"
     ]
    }
   ],
   "source": [
    "print(t)\n",
    "print(len(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "cam_res = 12\n",
    "stride = 2\n",
    "w = 1\n",
    "d = 1\n",
    "t = hor_connections(cam_res, 5, 5, stride, cam_res, w, d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(37, 65, 0.054, 1), (38, 65, 0.242, 1), (39, 65, 0.3989, 1), (40, 65, 0.242, 1), (41, 65, 0.054, 1), (42, 65, 0.242, 1), (43, 65, 0.3989, 1), (44, 65, 0.242, 1), (45, 65, 0.054, 1), (49, 65, 0.054, 1), (50, 65, 0.242, 1), (51, 65, 0.3989, 1), (52, 65, 0.242, 1), (53, 65, 0.054, 1), (54, 65, 0.242, 1), (55, 65, 0.3989, 1), (56, 65, 0.242, 1), (57, 65, 0.054, 1), (61, 65, 0.054, 1), (62, 65, 0.242, 1), (63, 65, 0.3989, 1), (64, 65, 0.242, 1), (65, 65, 0.054, 1), (66, 65, 0.242, 1), (67, 65, 0.3989, 1), (68, 65, 0.242, 1), (69, 65, 0.054, 1), (73, 65, 0.054, 1), (74, 65, 0.242, 1), (75, 65, 0.3989, 1), (76, 65, 0.242, 1), (77, 65, 0.054, 1), (78, 65, 0.242, 1), (79, 65, 0.3989, 1), (80, 65, 0.242, 1), (81, 65, 0.054, 1), (85, 65, 0.054, 1), (86, 65, 0.242, 1), (87, 65, 0.3989, 1), (88, 65, 0.242, 1), (89, 65, 0.054, 1), (90, 65, 0.242, 1), (91, 65, 0.3989, 1), (92, 65, 0.242, 1), (93, 65, 0.054, 1)]\n",
      "45\n"
     ]
    }
   ],
   "source": [
    "print(sorted(t))\n",
    "print(len(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(37, 65, 0.054, 1), (38, 65, 0.242, 1), (39, 65, 0.3989, 1), (40, 65, 0.242, 1), (41, 65, 0.054, 1), (42, 65, 0.242, 1), (43, 65, 0.3989, 1), (44, 65, 0.242, 1), (45, 65, 0.054, 1), (49, 65, 0.054, 1), (50, 65, 0.242, 1), (51, 65, 0.3989, 1), (52, 65, 0.242, 1), (53, 65, 0.054, 1), (54, 65, 0.242, 1), (55, 65, 0.3989, 1), (56, 65, 0.242, 1), (57, 65, 0.054, 1), (61, 65, 0.054, 1), (62, 65, 0.242, 1), (63, 65, 0.3989, 1), (64, 65, 0.242, 1), (65, 65, 0.054, 1), (66, 65, 0.242, 1), (67, 65, 0.3989, 1), (68, 65, 0.242, 1), (69, 65, 0.054, 1), (73, 65, 0.054, 1), (74, 65, 0.242, 1), (75, 65, 0.3989, 1), (76, 65, 0.242, 1), (77, 65, 0.054, 1), (78, 65, 0.242, 1), (79, 65, 0.3989, 1), (80, 65, 0.242, 1), (81, 65, 0.054, 1), (85, 65, 0.054, 1), (86, 65, 0.242, 1), (87, 65, 0.3989, 1), (88, 65, 0.242, 1), (89, 65, 0.054, 1), (90, 65, 0.242, 1), (91, 65, 0.3989, 1), (92, 65, 0.242, 1), (93, 65, 0.054, 1)]\n"
     ]
    }
   ],
   "source": [
    "print(sorted(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "cam_res = 12\n",
    "stride = 2\n",
    "w = 1\n",
    "d = 1\n",
    "t = left_diag_connections(cam_res, 5, 5, stride, cam_res, w, d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(17, 65, 1, 1), (30, 65, 1, 1), (43, 65, 1, 1), (56, 65, 1, 1), (61, 65, 1, 1), (69, 65, 1, 1), (74, 65, 1, 1), (87, 65, 1, 1), (100, 65, 1, 1), (113, 65, 1, 1)]\n"
     ]
    }
   ],
   "source": [
    "print(sorted(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def my_right_diag_connections(r1, x, y, stride, r2, w, d):\n",
    "    \"\"\"\n",
    "    Assume r1 is equal to r2\n",
    "\n",
    "    Given an (x,y) point in a square of size r2 x r2 find the \n",
    "    neurons which model the left diagonal \\ sides of a square of size \n",
    "    2 * stride + 1 in the square r1 x r1\n",
    "\n",
    "               x\n",
    "    +--------------------+\n",
    "    |     \n",
    "    |\n",
    "    |  .   (x,y)\n",
    "    |   \\\n",
    "    |    \\\n",
    "    |     .\n",
    "    |\n",
    "    +--------------------+\n",
    "\n",
    "    \"\"\"\n",
    "    out = []\n",
    "\n",
    "    for j, gw in enumerate(GAUSSIAN_WEIGHTS):\n",
    "        gaussians = list(range(-(len(GAUSSIAN_WEIGHTS)//2), len(GAUSSIAN_WEIGHTS)//2 +1))\n",
    "        \n",
    "        for i in range(0, 2 * stride + 1):\n",
    "            # Left side \n",
    "            pre_x = x-2*stride+i + gaussians[j]\n",
    "            pre_y = y-i + gaussians[j]\n",
    "            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y, r2), w*gw, d))\n",
    "        \n",
    "            # Bottom side\n",
    "            pre_x = x+i + gaussians[j]\n",
    "            pre_y = y+2*stride-i + gaussians[j]\n",
    "            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y, r2), w*gw, d))\n",
    "\n",
    "\n",
    "    out = filter_connections(out)\n",
    "\n",
    "    return list(set(out))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(2, 65, 0.054, 1), (4, 65, 0.242, 1), (13, 65, 0.054, 1), (15, 65, 0.242, 1), (17, 65, 0.3989, 1), (24, 65, 0.054, 1), (26, 65, 0.242, 1), (28, 65, 0.3989, 1), (30, 65, 0.242, 1), (37, 65, 0.242, 1), (39, 65, 0.3989, 1), (41, 65, 0.242, 1), (43, 65, 0.054, 1), (48, 65, 0.242, 1), (50, 65, 0.3989, 1), (52, 65, 0.242, 1), (54, 65, 0.054, 1), (56, 65, 0.242, 1), (61, 65, 0.3989, 1), (63, 65, 0.242, 1), (65, 65, 0.054, 1), (67, 65, 0.242, 1), (69, 65, 0.3989, 1), (74, 65, 0.242, 1), (76, 65, 0.054, 1), (78, 65, 0.242, 1), (80, 65, 0.3989, 1), (82, 65, 0.242, 1), (87, 65, 0.054, 1), (89, 65, 0.242, 1), (91, 65, 0.3989, 1), (93, 65, 0.242, 1), (95, 65, 0.054, 1), (100, 65, 0.242, 1), (102, 65, 0.3989, 1), (104, 65, 0.242, 1), (106, 65, 0.054, 1), (113, 65, 0.3989, 1), (115, 65, 0.242, 1), (117, 65, 0.054, 1), (126, 65, 0.242, 1), (128, 65, 0.054, 1), (139, 65, 0.054, 1)]\n",
      "43\n"
     ]
    }
   ],
   "source": [
    "t = sorted(right_diag_connections(cam_res, 5, 5, stride, cam_res, w, d))\n",
    "print(t)\n",
    "print(len(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
